# Maintainer: Some One <some.one@some.email.com>

_realname=squirrel
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=3.1
pkgrel=2
pkgdesc="A light-weight scripting language that fits in the size, memory bandwidth, and real-time requirements of applications like video games (mingw-w64)"
arch=('any')
url='http://www.squirrel-lang.org'
license=('MIT')
makedepends=("${MINGW_PACKAGE_PREFIX}-cmake")
source=("https://sourceforge.net/projects/squirrel/files/squirrel3/squirrel%20${pkgver}%20stable/${_realname}_${pkgver//./_}_stable.tar.gz"
         squirrel-3.1-1-cmake-name.patch)
sha256sums=('4845a7fb82e4740bde01b0854112e3bb92a0816ad959c5758236e73f4409d0cb'
            '4c661e1d9840a519ba6d7f6ccd0383a0767b4f1d5295fca1d35fb72ceafca54b')

# Helper macros to help make tasks easier #
apply_patch_with_msg() {
  for _patch in "$@"
  do
    msg2 "Applying $_patch"
    patch -Nbp1 -i "${srcdir}/$_patch"
  done
}

del_file_exists() {
  for _fname in "$@"
  do
    if [ -f $_fname ]; then
      rm -rf $_fname
    fi
  done
}
# =========================================== #

prepare() {
  cd ${srcdir}/${_realname}3
  apply_patch_with_msg squirrel-3.1-1-cmake-name.patch
}

build() {
  cd "${srcdir}"/${_realname}3
  [[ -d "${srcdir}"/build-${CARCH} ]] && rm -rf "${srcdir}"/build-${CARCH}
  mkdir -p "${srcdir}"/build-${CARCH} && cd "${srcdir}"/build-${CARCH}

  declare -a extra_config
  if check_option "debug" "n"; then
    extra_config+=("-DCMAKE_BUILD_TYPE=Release")
  else
    extra_config+=("-DCMAKE_BUILD_TYPE=Debug")
  fi

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
    ${MINGW_PREFIX}/bin/cmake \
      -G'MSYS Makefiles' \
      -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
      "${extra_config[@]}" \
      -DBUILD_SHARED_LIBS=ON \
      -DINSTALL_INC_DIR=include \
      ../${_realname}3

  make

}

#check() {
#  cd "${srcdir}"/build-${CARCH}
#  make check
#}

package() {
  cd "${srcdir}"/build-${CARCH}
  make install DESTDIR="${pkgdir}"

#  install -Dm644 ${srcdir}/${_realname}-${pkgver}/LICENSE ${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE
}
